module SalaryLog
  extend ActiveSupport::Concern

  def subsidy
    read_attribute(:subsidy) || {}
  end

  def subsidy_by(name)
    subsidy[name]
  end

  #岗位
  def gangwei
    subsidy["gangwei"].to_f
  end

  #住宿
  def zhusu
    subsidy["zhusu"].to_f
  end

  #餐补
  def canfei
    subsidy["canfei"].to_f
  end

  # 劳保
  def laobao
    subsidy["laobao"].to_f
  end

  #交通
  def jiaotong
    subsidy["jiaotong"].to_f
  end

  #高温
  def gaowen
    subsidy["gaowen"].to_f
  end

  def other_subsidy
    subsidy["other"].to_f
  end

  def subsidy_amount
    read_attribute(:subsidy_amount) || (gangwei + zhusu + canfei + laobao + jiaotong + gaowen + other_subsidy) || 0.0
  end

  def insurance
    read_attribute(:insurance) || {}
  end

  def yiliao
    insurance["yiliao"].to_f
  end

  def yanglao
    insurance["yanglao"].to_f
  end

  def shiye
    insurance["shiye"].to_f
  end

  def gongjijin
    insurance['gongjijin'].to_f
  end

  def insurance_amount
    read_attribute(:insurance_amount) || (yiliao + yanglao + shiye + gongjijin) ||  0.0
  end
end
